package com.sktlab.bizconfmobile.activity;

import java.util.List;

import com.sktlab.bizconfmobile.R;
import com.sktlab.bizconfmobile.adapter.AccessNumberAdapter;
import com.sktlab.bizconfmobile.model.AccessNumber;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

public class AccessNumberActivity extends BaseActivity {
	
	public static final String TAG = "AccessNumberActivity";
	public static final String KEY_ACCESS_NUMBER = "access_number";
	public static final String NOT_SELECTED_NUMBER = "null";
	
	private ListView mLv;
	private AccessNumberAdapter mAdapter;
	private List<AccessNumber> mDatas;
	private int pos = -1;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.activity_access_number);
		
		mLv = (ListView) findViewById(R.id.lv_access_number);	
		mDatas = AppClass.getInstance().getAccessNumberList();
		
		mAdapter = new AccessNumberAdapter(mDatas);
		
		mLv.setAdapter(mAdapter);
		mLv.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				
				pos = position;
				finish();
			}
		});
	}

	@Override
	protected void onResume() {
		super.onResume();
		
	}

	@Override
	public void finish() {
		
		Intent data = new Intent();
		
		if(pos >= 0) {
			
			AccessNumber an = mDatas.get(pos);
			//AppClass.getInstance().setAccessNumber(an.getNumber());		
			String number = an.getNumber();
			
			data.putExtra(KEY_ACCESS_NUMBER, number);
		}else {
			
			data.putExtra(KEY_ACCESS_NUMBER, NOT_SELECTED_NUMBER);
		}
		
		setResult(RESULT_OK, data);
		
		super.finish();
	}	
	
	
}
